package com.example.textview.frament;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
//import android.widget.FrameLayout;

import com.example.textview.R;

public class ContainerActivity extends AppCompatActivity implements AFragment.IOnMessageClick {


    Button mbtnchange;
    AFragment aFragment;
    BFragment bFragment;
    TextView mtv_Title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_container);
//.add(R.id.fl_container,aFragment).commitAllowingStateLoss();

        mtv_Title=findViewById(R.id.tv_title);
        aFragment=new AFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.fl_container,aFragment).commitAllowingStateLoss();

        mbtnchange = findViewById(R.id.btn_change);
        mbtnchange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bFragment=new BFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.fl_container,bFragment).commitAllowingStateLoss();
            }
        });


    }

    @Override
    public void onCclik(String msg) {
        mtv_Title.setText(msg);
    }
}